Namespace Collections
  ''' <summary>
  ''' Array Helper Class
  ''' </summary>
  ''' <remarks></remarks>
  Public NotInheritable Class ArrayHelper
    Private Const DEFAULT_STRING_DELIM As Char = ","c
    ''' <summary>
    ''' Converts values in an array to a delimited string.
    ''' </summary>
    ''' <param name="array">Array to convert</param>
    ''' <returns>Delimited String</returns>
    ''' <remarks>Default delimiter is ","</remarks>
        Public Shared Function ConvertArrayToString(Of TArray As {IEnumerable})(ByVal array As TArray()) As String

            Return ConvertArrayToString(array, DEFAULT_STRING_DELIM)

        End Function

    ''' <summary>
    ''' Converts valus in an array to a delimited string.
    ''' </summary>
    ''' <param name="array">Array to convert</param>
    ''' <param name="separator">Character to delimit Array.</param>
    ''' <returns>Delimited String</returns>
    ''' <remarks></remarks>
        Public Shared Function ConvertArrayToString(Of TArray As {IEnumerable})(ByVal array As TArray(), ByVal separator As Char) As String

            If Not IsValidArray(array) Then
                Throw New ArgumentNullException("array")
            End If

            If IsNothing(separator) Then
                Throw New ArgumentNullException("separator")
            End If

            Dim result As New System.Text.StringBuilder

            For Each arrayItem As TArray In array
                If result.Length > 0 Then
                    result.Append(separator)
                End If

                result.Append(arrayItem.ToString)

            Next

            Return result.ToString

        End Function

    ''' <summary>
    ''' Verifies an array has elements.
    ''' </summary>
    ''' <param name="array">Array to verify</param>
    ''' <returns>True if a valid array</returns>
    ''' <remarks></remarks>
    Public Shared Function IsValidArray(ByVal array As Array) As Boolean
      Dim valid As Boolean = False

      If array Is Nothing Then
        Throw New ArgumentNullException("array")
      End If

      If (array IsNot Nothing) AndAlso (array.Length > 0) Then
        valid = True
      End If

      Return valid

    End Function


    Private Sub New()
    End Sub

  End Class
End Namespace
